package com.ihg.hiex.entity.session.participator;

import java.beans.Transient;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.ihg.hiex.entity.session.Session;
import com.ihg.hiex.entity.user.Assessor;
import com.ihg.hiex.entity.user.Delegate;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "session_participator")
public class SessionParticipator {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Session session;
    
    /**
     * 评测人Id
     */
    private Long assessorId;
    
    /**
     * 冗余字段
     * 评测人名称
     */
    private String assessorName;
    
    /**
     * 受评人Id
     */
    private Long delegateId;
    
    /**
     * 冗余字段
     * 受评人名称
     */
    private String delegateName;
    
    /**
     * 所属的sub session
     * 可能字段 A/B
     */
    private String subSession;
    
    /**
     * 所属分组ID
     * 可能字段 A/B/C/D/E/F/G...
     */
    private String subgroup;
    
    /**
     * 在某一个group中ASSESSOR的seat
     * 可能字段 1/2
     */
    private String assessorSeat;
    
    /**
     * 在某一个group中DELEGATE的seat
     * 可能字段 1/2/3/4
     */
    private String delegateSeat;
    
    private Date createTime;
    
    private Date lastModifyTime;
    
    private Long lastOperator;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public SessionParticipator() {
    }
    
    /**
     * 
     * @param session
     * @param assessor
     * @param delegate
     * @param subSession
     * @param subgroup
     * @param assessorSeat
     * @param delegateSeat
     * @param operator
     */
    public SessionParticipator(Session session, Assessor assessor, Delegate delegate,
                               String subSession, String subgroup, String assessorSeat, String delegateSeat, Long operator) {
        this.session = session;
        this.assessorId = assessor.getId();
        this.assessorName = assessor.getName();
        this.delegateId = delegate.getId();
        this.delegateName = delegate.getName();
        this.subSession = subSession;
        this.subgroup = subgroup;
        this.assessorSeat = assessorSeat;
        this.delegateSeat = delegateSeat;
        this.createTime = new Date();
        this.lastModifyTime = new Date();
        this.lastOperator = operator;
        this.disabled = false;
    }
    
    /**
     * 
     * @param delegateId
     * @param delegateName
     * @return
     */
    public SessionParticipator editDelegate(Long delegateId, String delegateName) {
        this.delegateId = delegateId;
        this.delegateName = delegateName;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean getDelegateLevel() {
        int seat = Integer.parseInt(this.delegateSeat);
        boolean result = true;
        if(seat % 2 == 0) {
            result = false;
        }
        return result;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getAssessorIdString() {
        return this.assessorId.toString();
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getDelegateIdString() {
        return this.delegateId.toString();
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the session
     */
    public Session getSession() {
        return session;
    }

    /**
     * @return the assessorId
     */
    public Long getAssessorId() {
        return assessorId;
    }

    /**
     * @return the assessorName
     */
    public String getAssessorName() {
        return assessorName;
    }

    /**
     * @return the delegateId
     */
    public Long getDelegateId() {
        return delegateId;
    }

    /**
     * @return the delegateName
     */
    public String getDelegateName() {
        return delegateName;
    }

    /**
     * @return the subSession
     */
    public String getSubSession() {
        return subSession;
    }

    /**
     * @return the subgroup
     */
    public String getSubgroup() {
        return subgroup;
    }

    /**
     * @return the assessorSeat
     */
    public String getAssessorSeat() {
        return assessorSeat;
    }

    /**
     * @return the delegateSeat
     */
    public String getDelegateSeat() {
        return delegateSeat;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Session session) {
        this.session = session;
    }

    /**
     * @param assessorId the assessorId to set
     */
    public void setAssessorId(Long assessorId) {
        this.assessorId = assessorId;
    }

    /**
     * @param assessorName the assessorName to set
     */
    public void setAssessorName(String assessorName) {
        this.assessorName = assessorName;
    }

    /**
     * @param delegateId the delegateId to set
     */
    public void setDelegateId(Long delegateId) {
        this.delegateId = delegateId;
    }

    /**
     * @param delegateName the delegateName to set
     */
    public void setDelegateName(String delegateName) {
        this.delegateName = delegateName;
    }

    /**
     * @param subSession the subSession to set
     */
    public void setSubSession(String subSession) {
        this.subSession = subSession;
    }

    /**
     * @param subgroup the subgroup to set
     */
    public void setSubgroup(String subgroup) {
        this.subgroup = subgroup;
    }

    /**
     * @param assessorSeat the assessorSeat to set
     */
    public void setAssessorSeat(String assessorSeat) {
        this.assessorSeat = assessorSeat;
    }

    /**
     * @param delegateSeat the delegateSeat to set
     */
    public void setDelegateSeat(String delegateSeat) {
        this.delegateSeat = delegateSeat;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
